package org.edu.modules.stu.bxxl.service.impl;

import org.apache.shiro.SecurityUtils;
import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.system.vo.LoginUser;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.stu.bxxl.mapper.VeStuInsuranceKnowledgeMapper;
import org.edu.modules.stu.bxxl.entity.VeStuInsuranceKnowledge;
import org.edu.modules.stu.bxxl.dto.VeStuInsuranceKnowledgeDto;
import org.edu.modules.stu.bxxl.service.VeStuInsuranceKnowledgeService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;



/**
 * 实现类
 */
@Service
public class VeStuInsuranceKnowledgeServiceImpl extends BaseServiceImpl<VeStuInsuranceKnowledge, VeStuInsuranceKnowledgeMapper> implements VeStuInsuranceKnowledgeService {

    public IPage<VeStuInsuranceKnowledgeDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeStuInsuranceKnowledgeDto findDtoById(String id) {
        VeStuInsuranceKnowledge entity = super.findById(id);
        VeStuInsuranceKnowledgeDto dto = ConvertUtils.convertToDto(entity, VeStuInsuranceKnowledgeDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeStuInsuranceKnowledgeDto dto,Boolean isAdd){
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (loginUser != null && loginUser.getId() != null) {
            dto.setUserId(loginUser.getId());
            dto.setUserName(loginUser.getRealname());
        }

        if(isAdd){
            super.insert(dto);
        }else{
            super.update(dto);
        }
    }

    @Override
    public void importExcel(List<Map<String, Object>> mapList){
        for (Map map: mapList) {
            VeStuInsuranceKnowledgeDto dto = new VeStuInsuranceKnowledgeDto();
                   //         dto.setTypeId ((String)map.get(0000));
                   //         dto.setTitle ((String)map.get(0000));
                   //         dto.setContent ((String)map.get(0000));
                   //         dto.setListNum ((String)map.get(0000));
                   //         dto.setUserId ((String)map.get(0000));
                   //         dto.setUserName ((String)map.get(0000));
                   //         dto.setStatus ((String)map.get(0000));
            
            super.insert(dto);
        }

    }

}
